﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DataAccess;
using DevExpress.XtraEditors;

namespace QuanLyKhachSan
{
    public partial class FormTimChiTietHoaDon : XtraForm,ITimKiem<ChiTietHoaDonDichVu>
    {
        public FormTimChiTietHoaDon()
        {
            InitializeComponent();
        }

        private void FormTimChiTietHoaDon_Load(object sender, EventArgs e)
        {

        }

        private Exception KiemTraThongTin()
        {
            var exception = new Exception();
            try
            {
                int.Parse(this.txtNoidungtim.Text);
                return exception;
            }
            catch (Exception)
            {
                return new Exception("Mã nhân viên phải là số nguyên");
            }
        }

        private void btnTim_Click(object sender, EventArgs e)
        {
            if (KiemTraThongTin().Message!=null)
            {
                Func<ChiTietHoaDonDichVu, bool> newFilter = ct => ct.MaDV.Equals(int.Parse(this.txtNoidungtim.Text));
                Result = new ChiTietHoaDonDVManager().GetAllOrdersDetail().Result.Where(newFilter);
                if (!Result.Any())
                {
                    XtraMessageBox.Show("Không tìm thấy");
                }
                else
                {
                    DialogResult = DialogResult.OK;
                }
            }
            else
            {
                this.lblInfo.Text = KiemTraThongTin().Message;
            }
        }

        public Func<ChiTietHoaDonDichVu, bool> Filter { get; set; }

        public IEnumerable<ChiTietHoaDonDichVu> Result { get; set; }

        private void txtNoidungtim_TextChanged(object sender, EventArgs e)
        {
            this.lblInfo.Text = "";
        }

        private void txtNoidungtim_TextChanged_1(object sender, EventArgs e)
        {
            lblInfo.Text = "";
        }
    }
}
